package com.cml.rpc.client;

import com.cml.rpc.loadbalance.LoadBalance;
import com.cml.rpc.loadbalance.RandomLoadBalance;
import com.cml.rpc.pojo.Blog;
import com.cml.rpc.pojo.User;
import com.cml.rpc.register.ServiceRegister;
import com.cml.rpc.register.ZkServiceRegister;
import com.cml.rpc.publicinterface.BlogService;
import com.cml.rpc.publicinterface.UserService;

/**
 * 客户端入口
 * 重构结构，松解耦，不同通信方式不同实现
 * 使用netty进行通信
 * @author cml
 *
 * @create 2021/7/21 12:57
 */
public class RpcClientMain {
    public static void main(String[] args) {
//        RpcClient simpleRpcClient = new SimpleRpcClient("127.0.0.1", 8877);
//        RpcClientProxy rpcClientProxy = new RpcClientProxy(simpleRpcClient);

//        NettyRpcClient nettyRpcClient = new NettyRpcClient("127.0.0.1", 8877);
        NettyRpcClient nettyRpcClient = new NettyRpcClient();
        RpcClientProxy rpcClientProxy = new RpcClientProxy(nettyRpcClient);
        UserService proxyUserService = rpcClientProxy.getProxy(UserService.class);
        User user = proxyUserService.getUserById(123);
        System.out.println("user = " + user);

        System.out.println("---------------");
        LoadBalance randomLoadBalance = new RandomLoadBalance();
        ServiceRegister zkServiceRegister = new ZkServiceRegister(randomLoadBalance);
        NettyRpcClient nettyRpcClient1 = new NettyRpcClient(zkServiceRegister);
        RpcClientProxy rpcClientProxy1 = new RpcClientProxy(nettyRpcClient1);
        BlogService proxyBlogService = rpcClientProxy1.getProxy(BlogService.class);
        Blog blog = proxyBlogService.getBlogById(111);
        System.out.println("blog = " + blog);

    }
}
